<?php

/**
 * Mapping table [cdb_threads]
 *
 * @category   app_M
 * @package    app_M
 * @author     
 * @copyright  Copyright (c)
 * @license
 */
class Posts extends Zend_Db_Table
{
    /**
     * The table name.
     *
     * @var string
     */
	protected function _setup()
	{
		$config = Zend_Registry::get('config');
		$this->_name = $config->db->config->prcode.'Posts';
		$this->_request = new Zend_Controller_Request_Http();
		parent::_setup();
	}
	
	/**
     * 取得主贴子
     */
	
	public function get_first_post($tid =0){
	     $select = $this->_db->select();
		 $select->from($this->_name, '*');
		 $select->where('tid = ?',$tid);
		 $select->where('first = ?', '1');
		 $select->join('cdb_memberfields', 'authorid = cdb_memberfields.uid', '*');
		 $rowset = $this->_db->fetchAll($select);
		 return $rowset;
		 		
	}
	 /**
     * 取得回复的贴子，并且分页处理
     */
	
	public function get_replies_posts($_page,$tid =0,$nums=10,$link='?'){
		 $where = $this->getAdapter()->quoteInto('tid = ?',$tid);
	     $total = $this->fetchAll($where)->count()-1;
	     $pager = new Pager($total,$nums,$_page);
         $count = $nums;
         $offset = $pager->_offset();
   	     $select = $this->_db->select();
		 $select->from($this->_name, '*');
		 $select->where('tid = ?',$tid);
		 $select->where('first = ?', '0');
		 $select->join('cdb_memberfields', 'authorid = cdb_memberfields.uid', '*');
		 $select->order('dateline');
		 $select->limit($count, $offset);
		 $rowset = $this->_db->fetchAll($select);
		 $this->pagurl= $pager->num_link($link);
	
		 return $rowset;
		 		
	}
}